﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics.Contracts;

namespace BE.Web.Betfair.Interface.Entities
{
    /// <summary>
    ///BetTypes
    /// </summary>
    public enum BackOrLay
    {
        /// <summary>
        /// Back Bet
        /// </summary>
        Back = 1,

        /// <summary>
        /// Offering lay
        /// </summary>
        Lay = 2,

        /// <summary>
        /// Not defined
        /// </summary>
        NotSet = 0
    }
    /// <summary>
    /// A bet
    /// </summary>
    public sealed class Bet
    {
        /// <summary>
        /// Bets the type to enum.
        /// </summary>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static BackOrLay BetTypeToEnum(string text)
        {
            #region condition
            Contract.Requires<ArgumentNullException>(text != null);
            Contract.Requires<ArgumentOutOfRangeException>(text == "B"   ||text =="L");
            Contract.Ensures(Contract.Result<BackOrLay>() != BackOrLay.NotSet);
            #endregion

            BackOrLay result;

            if (text == "B")
            {
                result = BackOrLay.Back;
            }
            else
            {
              result = BackOrLay.Lay;
            }

            return result;

        }
        /// <summary>
        /// The Id of the Bet
        /// </summary>
        public long Id { get; private set; }

        /// <summary>
        /// Name of the Bet
        /// </summary>
        public string MarketFullName { get; private set; }


        /// <summary>
        /// Type of the Bet
        /// </summary>
        /// <value>The type of the bet.</value>
        public BackOrLay BetType { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="Bet"/> class.
        /// </summary>
        public Bet()
        {


        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Bet"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="marketName">The name of the markted.</param>
        /// <param name="betType">The bettype</param>
        public Bet(long id, string marketName,string betType)
        {
            #region condition
            Contract.Requires<ArgumentNullException>(betType != null);
            Contract.Requires<ArgumentOutOfRangeException>(betType == "B" || betType == "L");
            Contract.Requires<ArgumentNullException>(marketName != null);
            #endregion

            this.Id = id;
            this.MarketFullName = marketName;

            this.BetType = BetTypeToEnum(marketName);
        }
    }
}
